﻿using MaterialDesignThemes.Wpf;
using Prism.Commands;
using StarryEdge.Core.Enums;
using StarryEdge.Core.Models;
using StarryEdge.Core.Parameter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StarryEdge.Menu.User.ViewModels.Dialog
{
    public class AddRolePopupDialog
    {
        private IUserEntity _userEentity;
        public RoleModel Role { get; set; }
        public AddRolePopupDialog(IUserEntity userEentity, RoleModel roleModel)
        {
            _userEentity = userEentity;
            if (roleModel == null)
            {
                Role = new RoleModel()
                {
                    Id = Guid.NewGuid(),
                    CreateTime = DateTime.Now,
                    IsEnabled = true,
                    Level = 1,
                };
            }
            else
            {
                Role = roleModel;
            }
        }

        public DelegateCommand Save => new DelegateCommand(() =>
        {
            _userEentity.AddRole(Role);
            _userEentity.Save();
            if (DialogHost.IsDialogOpen(PopUpTypes.Global.ToString()))
            {
                DialogHost.Close(PopUpTypes.Global.ToString());
            }
        });
    }
}
